<template>
  <div class="login-container">
    <div class="login-bg"></div>
    <div class="login-box">
      <div class="login-logo">
        <img src="https://img.alicdn.com/imgextra/i4/O1CN01Qn1QwC1w1Qn1QwC1Qn1QwC_!!6000000000000-2-tps-200-200.png" alt="logo" />
        <span>i点餐后台系统</span>
      </div>
      <h2>欢迎登录</h2>
      <el-form :model="form" class="login-form">
        <el-form-item>
          <el-input v-model="form.username" placeholder="用户名">
            <template #prefix>
              <el-icon><i-ep-user /></el-icon>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="form.password" placeholder="密码" type="password">
            <template #prefix>
              <el-icon><i-ep-lock /></el-icon>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="login-btn" @click="handleLogin">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import axios from 'axios'
import baseURL from '../config/baseURL'
import { useRouter } from 'vue-router'
import { User as IepUser, Lock as IepLock } from '@element-plus/icons-vue'

const router = useRouter()
const form = ref({
  username: '',
  password: ''
})

const handleLogin = async () => {
  try {
    const res = await axios.post(baseURL + '/auth/login', {
      username: form.value.username,
      password: form.value.password
    })
    if (res.data.code === 1) {
      localStorage.setItem('token', res.data.data)
      ElMessage.success('登录成功')
      router.push('/')
    } else {
      ElMessage.error(res.data.message || '登录失败')
    }
  } catch (e) {
    ElMessage.error('网络错误')
  }
}
</script>

<style scoped>
.login-container {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  min-height: 100vh;
  width: 100vw;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
  z-index: 9999;
}
.login-bg {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: url('https://pic.imgdb.cn/item/65f6e2e79f345e8d03e2e2e2.jpg') center/cover no-repeat;
  opacity: 0.15;
  z-index: 1;
}
.login-box {
  position: relative;
  z-index: 2;
  width: 380px;
  padding: 36px 32px 28px 32px;
  background: rgba(255,255,255,0.95);
  border-radius: 16px;
  box-shadow: 0 4px 32px rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
}
.login-logo img {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  margin-right: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.login-logo span {
  font-size: 22px;
  font-weight: 700;
  color: #ff6f91;
  letter-spacing: 2px;
}
.login-box h2 {
  text-align: center;
  margin-bottom: 24px;
  font-weight: 600;
  color: #333;
  font-size: 22px;
  letter-spacing: 1px;
}
.login-form {
  margin-top: 10px;
  width: 100%;
}
.el-input {
  height: 44px;
  font-size: 16px;
}
.el-input__wrapper {
  border-radius: 8px;
}
.login-btn {
  width: 100%;
  height: 44px;
  font-size: 18px;
  border-radius: 8px;
  background: linear-gradient(90deg, #ffb6b9 0%, #fcdff0 100%);
  color: #fff;
  font-weight: 600;
  letter-spacing: 2px;
  box-shadow: 0 2px 8px rgba(255,182,185,0.15);
  transition: background 0.3s, box-shadow 0.3s;
}
.login-btn:hover {
  background: linear-gradient(90deg, #ff6f91 0%, #fcdff0 100%);
  box-shadow: 0 4px 16px rgba(255,111,145,0.18);
}
</style> 